define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'register/index' + location.search,
                    add_url: 'register/add',
                    edit_url: 'register/edit',
                    del_url: 'register/del',
                    multi_url: 'register/multi',
                    table: 'register',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'tripmode', title: __('Tripmode'), searchList: {"0":__('Tripmode 0'),"1":__('Tripmode 1'),"2":__('Tripmode 2'),"3":__('Tripmode 3'),"4":__('Tripmode 4')}, formatter: Table.api.formatter.normal},
                        {field: 'inout', title: __('Inout'), searchList: {"1":__('Inout 1'),"2":__('Inout 2')}, formatter: Table.api.formatter.normal},
                        {field: 'c_time', title: __('C_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'temperature', title: __('Temperature'), operate:'BETWEEN'},
                        {field: 'symptomstr', title: __('Symptomstr')},
                        {field: 'carnumber', title: __('Carnumber')},
                        {field: 'quarters.name', title: __('Quarters.name')},
                        {field: 'user.nickname', title: __('User.nickname')},
                        {field: 'user.headimgurl', title: __('User.headimgurl'),events: Table.api.events.image,  formatter: Table.api.formatter.image},
                        {field: 'user.name', title: __('User.name')},
                        {field: 'user.phone', title: __('User.phone')},
                        {field: 'user.housenumber', title: __('User.housenumber')},
                        {field: 'user.islocal', title: __('User.islocal'),searchList: {"0":'不是',"1":'是'}, formatter: Table.api.formatter.normal},

                        {field: 'user.address', title: __('User.address')},
                        {field: 'user.sex', title: __('User.sex'),searchList: {"0":'未知',"1":'男',"2":'女'}, formatter: Table.api.formatter.normal},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});